/**
 * 广寒宫
 * 网址:www.guanghangong.xyz
 */
package com.moon.admin.framework.springmvc.domain;

import lombok.Data;

/**
 * 返回结果
 * @author ninglong
 */
@Data
public class R<T> {

	private int code;
	/** 返回的用户展示的详细信息*/
	private String msg;
	/** 返回的具体数据*/
	private T data;
	
	public static <T> R<T> status(Boolean status) {
		if(status) {
			return success();
		}
		return fail(RCode.FAIL.getMsg());
	}

	public static <T> R<T> fail(String msg) {
		return fail(RCode.FAIL.getCode(), msg);
	}
	
	public static <T> R<T> fail(int code, String msg) {
		R<T> r = new R<>();
		r.setCode(code);
		r.setMsg(msg);
		return r;
	}

	public static <T> R<T> success() {
		R<T> r = new R<>();
		r.setCode(RCode.SUCCESS.getCode());
		r.setMsg(RCode.SUCCESS.getMsg());
		return r;
	}

	public static <T> R<T> success(T t) {
		return success(t,RCode.SUCCESS.getCode(),RCode.SUCCESS.getMsg());
	}

	public static <T> R<T> success(T t,int code, String msg) {
		R<T> r = new R<>();
		r.setCode(code);
		r.setData(t);
		r.setMsg(msg);
		return r;
	}
}